package com.hmkj.core.api.ufx.model.res;

import com.xiaoleilu.hutool.util.StrUtil;
import lombok.Data;

import java.util.Map;

/**
 * 期货委托回报
 *
 * @author Vector
 * @create 2017-11-14 16:08
 */
@Data
public class EntrustPush {
    /**
     * 目标机构号
     */
    private String companyId;
    /**
     * 发送者机构号
     */
    private String senderId;
    /**
     * 委托编号
     */
    private String futuEntrustNo;
    /**
     * 交易类别
     */
    private String futuExchType;
    /**
     * 买卖方向
     */
    private String entrustBs;
    /**
     * 品种代码类别
     */
    private String commodityType;
    /**
     * 合约代码
     */
    private String contractCode;
    /**
     * 第二腿合约代码
     */
    private String secondCode;
    /**
     * 产品类型
     */
    private String futuProductType;
    /**
     * 资产账户
     */
    private String fundAccount;
    /**
     * 委托状态
     */
    private String futuEntrustStatus;
    /**
     * 成交数量
     */
    private int businessAmount;
    /**
     * 提示信息
     */
    private String errorMessage;
    /**
     * 委托数量
     */
    private int entrustAmount;
    /**
     * 委托引用
     */
    private String entrustReference;

    // msg_type|company_id|sender_id|futu_entrust_no|entrust_bs|futu_product_type|futu_exch_type|commodity_type|contract_code|second_code|
    // options_type|strike_price|entrust_amount|business_amount|fund_account|futu_entrust_status|error_message|
    public static EntrustPush buildData(Map<String, String> datas,String topic) {
        EntrustPush ep = new EntrustPush();
        if ("futu.trade_push".equals(topic)){
            // 内盘期货
            ep.setCompanyId(datas.get("company_id"));
            ep.setSenderId(datas.get("sender_id"));
            ep.setFutuEntrustNo(datas.get("entrust_no"));
            ep.setEntrustBs(datas.get("entrust_bs"));
            ep.setFutuExchType(datas.get("futu_exch_type"));
            ep.setCommodityType(datas.get("commodity_type"));
            ep.setContractCode(datas.get("contract_code").replace(ep.getCommodityType(),""));
            ep.setFundAccount(datas.get("fund_account"));
            ep.setFutuEntrustStatus(datas.get("entrust_status"));
            ep.setBusinessAmount(StrUtil.isBlank(datas.get("business_amount")) ? 0 : Integer.parseInt(datas.get("business_amount")));
            ep.setEntrustAmount(StrUtil.isBlank(datas.get("entrust_amount")) ? 0 : Integer.parseInt(datas.get("entrust_amount")));
            ep.setEntrustReference(datas.get("entrust_reference"));
            ep.setErrorMessage(datas.get("error_message"));
        }else {
            // 外盘期货
            ep.setCompanyId(datas.get("company_id"));
            ep.setSenderId(datas.get("sender_id"));
            ep.setFutuEntrustNo(datas.get("futu_entrust_no"));
            ep.setEntrustBs(datas.get("entrust_bs"));
            ep.setFutuExchType(datas.get("futu_exch_type"));
            ep.setCommodityType(datas.get("commodity_type"));
            ep.setContractCode(datas.get("contract_code"));
            ep.setFundAccount(datas.get("fund_account"));
            ep.setFutuEntrustStatus(datas.get("futu_entrust_status"));
            ep.setBusinessAmount(StrUtil.isBlank(datas.get("business_amount")) ? 0 : Integer.parseInt(datas.get("business_amount")));
            ep.setEntrustAmount(StrUtil.isBlank(datas.get("entrust_amount")) ? 0 : Integer.parseInt(datas.get("entrust_amount")));
            ep.setEntrustReference(datas.get("entrust_reference"));
            ep.setErrorMessage(datas.get("error_message"));
        }
        return ep;
    }
}
